package com.example.repoprovider.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * 库存TCC 处理器
 * @author Kong
 * @date 2021-9-14 16:44
 */
@LocalTCC
public interface IRepoAction {
    /**
     * prepare阶段，冻结库存
     * @param businessActionContext
     * @param productCode
     * @param amount
     * @return
     */
    @TwoPhaseBusinessAction(name = "repoAction",commitMethod = "commitDecrease",rollbackMethod = "rollbackDecrease")
    boolean prepareDecreaseRepo(BusinessActionContext businessActionContext,
                                @BusinessActionContextParameter(paramName = "productCode")String productCode,
                                @BusinessActionContextParameter(paramName = "amount") Integer amount);

    /**
     * 二阶段提交
     * @param businessActionContext
     * @return
     */
    boolean commitDecrease(BusinessActionContext businessActionContext);

    /**
     * 二阶段回滚
     * @param businessActionContext
     * @return
     */
    boolean rollbackDecrease(BusinessActionContext businessActionContext);


}
